package com.sky.mapper;

import com.sky.entity.SetmealDish;
import com.sky.vo.DishItemVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author : jiang
 * @date : 2023/10/16 9:17
 */
@Mapper
public interface SetmealDishMapper {

    /**
     * 根据菜品id查询关联套餐数量
     * @param id
     * @return
     */
    @Select("select count(*) from setmeal_dish where dish_id = #{id}")
    Integer countByDishId(Long id);

    /**
     * 根据套餐id删除数据
     * @param ids
     */
    void deleteById(List<Long> ids);

    /**
     * 添加套餐关联的菜品
     * @param dish
     */
    void addSetmealDish(List<SetmealDish> dish);

    /**
     * 根据套餐id查询菜品
     * @param id
     * @return
     */
    @Select("select * from setmeal_dish where setmeal_id = #{id}")
    List<SetmealDish> getDishBySetmealId(Long id);

    /**
     * 根据套餐id查询菜品
     * @param id
     * @return
     */
    @Select("select sd.name, sd.copies, d.image, d.description " +
            "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{id}")
    List<DishItemVO> getDishBySetmeal(Long id);

}
